package com.action.commute;

import java.util.*;

import com.common.*;
import com.db.commute.*;

public class ListDayAction {
	private Date prevday;
	private Date today;
	private Date nextday;
	private String sdate;
	private int sabun;
	private List<Object> listd;
	private int curpage = 1;
	private int totalpage;
	private int lpp = 10;
	
	private CommuteDAO commDAO;
	private DateProcess dateProc;
	private ListProcess listProc;
	
	public void setListProc(ListProcess listProc) {
		this.listProc = listProc;
	}
	public void setDateProc(DateProcess dateProc) {
		this.dateProc = dateProc;
	}
	public void setSabun(int sabun) {
		this.sabun = sabun;
	}
	public void setCommDAO(CommuteDAO commDAO) {
		this.commDAO = commDAO;
	}
	public Date getPrevday() {
		return prevday;
	}
	public Date getToday() {
		return today;
	}
	public void setSdate(String sdate) {
		this.sdate = sdate;
	}
	public Date getNextday() {
		return nextday;
	}
	public List<Object> getListd() {
		return listd;
	}
	
	public int getCurpage() {
		return curpage;
	}
	public void setCurpage(int curpage) {
		this.curpage = curpage;
	}
	public int getTotalpage() {
		return totalpage;
	}
	public void setLpp(int lpp) {
		this.lpp = lpp;
	}
	
	public String execute(){
		String result = "";		
		try {
			if(sdate == null || sdate.equals("newd")){
				today = new Date();
			}else{				
				today = dateProc.valueToDate(sdate);
			}
			CommuteVO commVO = new CommuteVO();			
			commVO.setSabun(sabun);
			commVO.setRegdate(today);
			listd = commDAO.getListDay(commVO);	
			Date days[] = dateProc.getDays(today);
			prevday = days[0];
			nextday = days[2];
			// 페이지 나누기
			totalpage = listProc.getTotalPage(listd, lpp);			
			System.out.println(curpage+"|"+lpp+"|"+totalpage+"|"+listd.toString());
			listd = listProc.createPage(curpage, lpp, totalpage, listd);
			System.out.println(listd.toString());
			result = "success";
		} catch (Exception e) {
			System.out.println("ListDayAction.execute():"+e.toString());			
			result = "error";
		}
		return result;
	}
}
